<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>销售订单列表</title>
    <link href="<%=path%>/css/core.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/pagination.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/list.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/xToolbar.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/jquery-impromptu.css" rel="stylesheet" type="text/css"/>
  </head>
  <body>
  	<div id="toolbar"></div>
  	<form id="listForm" action="<%=path%>/sales/salesOrder/listPagination.t4m" method="post">
      <table id="titleTable" cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" id="allBox"/></td>
          <td>编号</td>
          <td>客户名称</td>
          <td>销售人员</td>
          <td>收货地址</td>
          <td>总金额</td>
          <td>订单日期</td>
		  <td>审批状态</td>
          <td>操作</td>
        </tr>
      </table>
      <table id="dataTable" cellpadding="0" cellspacing="0">
        <s:iterator id="salesOrder" value="page.list" status="i">
          <tr class="row" ondblclick="viewOrder('<s:property value="#salesOrder.id"/>')">
            <td class="num"><s:property value="#i.index+1"/></td>
            <td class="box">
         	  <s:if test="#salesOrder.auditState != 2">
              	<input type="checkbox" name="idList" value="<s:property value="#salesOrder.id"/>"/>
              </s:if>
            </td>
            <td><span><s:property value="#salesOrder.code"/></span></td>
            <td><span><s:property value="#salesOrder.customer.name"/></span></td>
            <td><span><s:property value="#salesOrder.saler.realName"/></span></td>
            <td><span><s:property value="#salesOrder.takeAddress"/></span></td>
            <td><span><s:property value="#salesOrder.totalPrice"/></span></td>
            <td><span><s:date name="#salesOrder.orderDate" format="yyyy-MM-dd"/></span></td>
			<td><s:property
					value="@org.jxc.vo.KeyValue@getHtml(@org.jxc.constants.JXCString@AUDIT_STATE, #salesOrder.auditState)" />
			</td>
			<td align="center">
			<s:if test="#salesOrder.auditState == 0 || #salesOrder.auditState == 3">
					<a
						href="javascript:applyBill('<s:property value="#salesOrder.id"/>')">提交申请</a>
				</s:if> <s:elseif
					test="#salesOrder.auditor.id == #session['LoginBean'].user.id && #salesOrder.auditState == 1">
					<a
						href="javascript:auditBill('<s:property value="#salesOrder.id"/>',2)">同意</a>
					<a
						href="javascript:auditBill('<s:property value="#salesOrder.id"/>',3)">驳回</a>
				</s:elseif>
                <s:elseif test="#salesOrder.auditState == 2 && #salesOrder.outState != 1 ">
					<a
						href="javascript:top.salesOrder.out('<s:property value="#salesOrder.id"/>')">生成出库单</a>
						</s:elseif>
				</td>
          </tr>
        </s:iterator>
      </table>
      <s:include value="/share/pagebar.jsp"/>
  	</form>
    
    <script src="<%=path%>/js/core.js" type="text/javascript"></script>
    <script src="<%=path%>/js/share.js" type="text/javascript"></script>
    <script src="<%=path%>/js/jquery.js" type="text/javascript"></script>
    <script src="<%=path%>/js/Grid.js" type="text/javascript"></script>
    <script src="<%=path%>/js/BoxSelect.js" type="text/javascript"></script>
    <script src="<%=path%>/js/xToolbar.js" type="text/javascript"></script>
    <script src="<%=path%>/js/xToolbar.items.js" type="text/javascript"></script>
    <script src="<%=path%>/js/jquery-impromptu.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      
      new Toolbar({
        id: '1',
        renderTo : 'toolbar',
        icon: '../../image/op.gif',
        items : [{
          type:'button',
          text:'新建',
          useable : '<s:property value="@org.team4.util.Meta@getOperate(\"saleOrder_new\")"/>',
          position: {
            a: '0px 0px',
            b: '0px -120px'
          },
          handler:function(){
            top.salesOrder.add();
          }
        },'-',{
          type : 'button',
          text : '修改',
          useable : '<s:property value="@org.team4.util.Meta@getOperate(\"saleOrder_edit\")"/>',
          position: {
            a: '-20px 0px',
            b: '-20px -120px'
          },
          handler : function(){
            if(getFirstID()) {
                top.salesOrder.update(getFirstID());
            }
          }
        },'-',{
	          type : 'button',
	          text : '删除',
	          position: {
	            a: '-40px 0px',
	            b: '-40px -120px'
	          },
	          useable : '<s:property value="@org.team4.util.Meta@getOperate(\"saleOrder_delete\")"/>',
	          handler : function(){
	        	  if(getFirstID())
	              {
	                var txt = '是否删除该信息？';
	                $.prompt(txt,{
	                  buttons:{删除:true,取消:false},
	                  callback: function(v,m) {
	                    if(v) {
	                      document.getElementById('listForm').action = '<%=path%>/sales/salesOrder/delete.t4m';
	                      document.getElementById('listForm').submit();
	                    }
	                  }
	                });
	              }
	          }
	        }]
      });
      
      new Grid({
        titleTable:'titleTable',
        dataTable:'dataTable',
        widths : [30,24,100,150,100,250,100,100,100],
        height : function(){return getGridHeight({toolbarId:'toolbar',hasPage:true});}
      });
      
      new BoxSelect({
        allId : 'allBox',
        boxName : 'idList'
      });
      
      loadReady();
    });
    function viewOrder(id) {
    	  top.salesOrder.view(id);
      }
    function applyBill(salesOrderId) {
    	document.getElementById("listForm").action = "<%=path%>/sales/salesOrder/apply.t4m?salesOrderId=" + salesOrderId;
    	document.getElementById("listForm").submit();
    }
    function auditBill(salesOrderId,result) {
    	document.getElementById("listForm").action = "<%=path%>/sales/salesOrder/audit.t4m?salesOrderId="
				+ salesOrderId + "&auditState=" + result;
		document.getElementById("listForm").submit();
	}
    </script>
  </body>
</html>